//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	CamlQueryBuilderMembershipItem.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

namespace Smart.Common.Entities
{
	public class CamlQueryBuilderMembershipItem<TExecutorType> : CamlQueryBuilderStatementItem<TExecutorType>
		where TExecutorType : class
	{
		/// <summary>
		/// Membership Type
		/// </summary>
		public MembershipType Type { get; set; }

		public CamlQueryBuilderMembershipItem(string field, MembershipType type)
			: base(field, null, "Membership", null)
		{
			Type = type;
		}

		/// <summary>
		/// Return Cache code
		/// </summary>
		public override int GetCacheCode()
		{
			return base.GetCacheCode() ^ Type.GetHashCode();
		}

		/// <summary>
		/// Format QueryBuilder statement
		/// </summary>
		public override string FormatQuery()
		{
			return
				string.Format("<{0} Type=\"{2}\"><FieldRef Name=\"{1}\"/></{0}>", Op, (Query == null ? Field : Query.Meta.FieldName(Field)), Type);
		}
	}
}